#!/usr/bin/env python
# -*- coding: utf-8 -*-

from BeautifulSoup import BeautifulSoup
import urllib2
import wx

class TagsCounter:
    
    def counter(self,url,tag):
        
        
        try:
            content = urllib2.urlopen(url)
            
        except:
            box=wx.MessageDialog(None, "CONNECTION ERROR", "TAGS COUNTER",wx.OK)
            
            if box.ShowModal()== wx.ID_OK:
                box.Destroy()
            pass
                    
            
        try:
            urlContent = content.read()
        
        except:
            box=wx.MessageDialog(None, "READING ERROR", "TAGS COUNTER",wx.OK)
            
            if box.ShowModal()== wx.ID_OK:
                box.Destroy()
            pass
            
        else:
            content.close()
            pass
        
        soup = BeautifulSoup(urlContent)
        
        htmlTags= soup.findAll(tag)
        
        return str(len(htmlTags))
        
    pass

            
            
        
            
            
            
    
    
    
